import {Input} from 'acud';

interface ColumnProps {
    edit?: boolean;
    handleChange: (value: any, index: any, key: any) => void;
}

const initData = [
    {
        key: '1',
        resolution: 'John Brown',
        level: 32,
        description: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
    },
    {
        key: '2',
        resolution: 'Jim Green',
        level: 42,
        description: 'London No. 2 Lake Park, London No. 2 Lake Park',
    },
    {
        key: '3',
        resolution: 'Joe Black',
        level: 32,
        description: 'Sidney No. 1 Lake Park, Sidney No. 1 Lake Park',
    },
];

const getColumns = (props: ColumnProps) => {
    const {edit = false, handleChange = () => {}} = props;
    return [
        {
            title: '分辨率',
            dataIndex: 'resolution',
            key: 'resolution',
            width: '25%',
            render: (t = '', {resolution = ''}, index: number) => {
                if (edit) {
                    return <Input defaultValue={resolution} onChange={(v) => handleChange(v.target.value, index, 'resolution')} />;
                }
                return <>{resolution}</>;
            },
        },
        {
            title: '缩放层级',
            dataIndex: 'level',
            key: 'level',
            width: '15%',
            render: (t = '', {level = 0}, index: number) => {
                if (!edit) {
                    return <Input defaultValue={level} onChange={(v) => handleChange(+v.target.value, index, 'level')} />;
                }
                return <>{level}</>;
            },
        },
        {
            title: '描述',
            dataIndex: 'description',
            key: 'description',
            width: '40%',
            render: (t = '', {description = ''}, index: number) => {
                if (!edit) {
                    return <Input defaultValue={description} onChange={(v) => handleChange(v.target.value, index, 'description')} />;
                }
                return <>{description}</>;
            },
        },
    ];
};

export {initData, getColumns};
